<%--
  Created by IntelliJ IDEA.
  User: HASEE
  Date: 2021/2/21
  Time: 20:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>开始页面</title>
    <script type="text/javascript" src="myjs/myjQuery.js"></script>
    <script>
        $(function () {
           $("#btn01").click(function () {
                $.ajax({
                    url:"mybatis/review",
                    type:"get",
                    dataType:"json",
                    success(resp){
                       $.each(resp,function (i,n) {
                        alert(n.id+""+n.name+""+n.email+""+n.age);
                       })
                    }

                })
           })

            $("#addBtn").click(function () {
                register()
            })
        })

        function register() {
            var id=$("#idInput").val()
            var name=$("#nameInput").val()
            var email=$("#emailInput").val()
            var age=$("#ageInput").val()
            $.ajax({
                url:"/mybatis/mybatis/register",
                type:"get",
                dataType: "json",
                data:{
                    id:id,
                    name:name,
                    email:email,
                    age:age
                },
                success:function (resp) {
                    if(resp.flag){
                        $("#span01").html("注册成功")
                    }else {
                        $("#span01").html("注册失败")
                    }
                }

            })
        }
    </script>
</head>
<body>
    <center>
        <h5 style="color: blue">mybatis的复习</h5><br>
        <button id="btn01">发起ajax请求,来查询person表中的所有数据</button>
        <button id="btn02">测试js</button><br>

        <form action="mybatis/register" method="get">
            id<input id="idInput" type="text" name="id"><br>
            名字<input id="nameInput" type="text" name="name"><br>
            邮箱<input id="emailInput" type="text" name="email"><br>
            年龄<input id="ageInput" type="text" name="age"><br>
            <input id="addBtn" type="button" value="注册">
            <br><span style="color:red" id="span01"></span>
        </form>

    </center>
</body>
</html>
